package com.entmanage.base.leave.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.entmanage.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.entmanage.common.utils.SecurityUtils;
import com.entmanage.base.leave.mapper.LeaveBalanceMapper;
import com.entmanage.base.leave.domain.LeaveBalance;
import com.entmanage.base.leave.service.ILeaveBalanceService;

/**
 * 员工假期管理Service业务层处理
 *
 * @author lsq
 * @date 2025-09-29
 */
@Service
public class LeaveBalanceServiceImpl implements ILeaveBalanceService
{
    @Autowired
    private LeaveBalanceMapper leaveBalanceMapper;

    /**
     * 查询员工假期管理
     *
     * @param id 员工假期管理主键
     * @return 员工假期管理
     */
    @Override
    public LeaveBalance selectLeaveBalanceById(Long id)
    {
        return leaveBalanceMapper.selectLeaveBalanceById(id);
    }

    /**
     * 查询员工假期管理列表
     *
     * @param leaveBalance 员工假期管理
     * @return 员工假期管理
     */
    @Override
    public List<LeaveBalance> selectLeaveBalanceList(LeaveBalance leaveBalance)
    {
        return leaveBalanceMapper.selectLeaveBalanceList(leaveBalance);
    }

    /**
     * 新增员工假期管理
     *
     * @param leaveBalance 员工假期管理
     * @return 结果
     */
    @Override
    public int insertLeaveBalance(LeaveBalance leaveBalance)
    {
        // 保存用户和部门ID
        leaveBalance.setUserId(SecurityUtils.getUserId());
        leaveBalance.setDeptId(SecurityUtils.getDeptId());
        leaveBalance.setCreateTime(DateUtils.getNowDate());
    leaveBalance.setCreateBy(SecurityUtils.getUsername());
        return leaveBalanceMapper.insertLeaveBalance(leaveBalance);
    }

    /**
     * 修改员工假期管理
     *
     * @param leaveBalance 员工假期管理
     * @return 结果
     */
    @Override
    public int updateLeaveBalance(LeaveBalance leaveBalance)
    {
        leaveBalance.setUpdateTime(DateUtils.getNowDate());
    leaveBalance.setUpdateBy(SecurityUtils.getUsername());
        return leaveBalanceMapper.updateLeaveBalance(leaveBalance);
    }

    /**
     * 批量删除员工假期管理
     *
     * @param ids 需要删除的员工假期管理主键
     * @return 结果
     */
    @Override
    public int deleteLeaveBalanceByIds(Long[] ids)
    {
        return leaveBalanceMapper.deleteLeaveBalanceByIds(ids);
    }

    /**
     * 删除员工假期管理信息
     *
     * @param id 员工假期管理主键
     * @return 结果
     */
    @Override
    public int deleteLeaveBalanceById(Long id)
    {
        return leaveBalanceMapper.deleteLeaveBalanceById(id);
    }

    @Override
    public Long selectEmpIdByUserId(Long userId) {
        return leaveBalanceMapper.selectEmpIdByUserId(userId);
    }

    @Override
    public List<LeaveBalance> selectLeaveBalanceByEmployeeId(Long employeeId) {
        return leaveBalanceMapper.selectByEmpId(employeeId);
    }

    @Override
    public List<LeaveBalance> findByEmployeeIdAndDelFlagNot2(Long employeeId) {
        return leaveBalanceMapper.findByEmployeeIdAndDelFlagNot2(employeeId);
    }

    @Override
    public int save(LeaveBalance entity) {
        return leaveBalanceMapper.insert(entity);
    }
    @Override
    public int updateById(LeaveBalance entity) {
        return leaveBalanceMapper.updateById(entity);
    }
}
